package org.jrfe.math.bound;

import org.jrfe.math.Vector2f;
import org.jrfe.util.FastMath;

public class BoundRect extends Bound {

	
	public BoundRect() {
		this(new Vector2f(), 0, 0);
	}

	public BoundRect(Vector2f center, float xExtent, float yExtent) {
		super(center,xExtent,yExtent);
		this.center = center;
		this.xExtent = xExtent;
		this.yExtent = yExtent;
	}
	
	public boolean intersects(BoundRect bb) {

		if (center.x + xExtent < bb.center.x - bb.xExtent
				|| center.x - xExtent > bb.center.x + bb.xExtent)
			return false;

		else if (center.y + yExtent < bb.center.y - bb.yExtent
				|| center.y - yExtent > bb.center.y + bb.yExtent)
			return false;

		return true;
	}

	@Override
	public boolean contains(Vector2f point) {
		return FastMath.abs(center.x - point.x) < xExtent
				&& FastMath.abs(center.y - point.y) < yExtent;
	}

	@Override
	public boolean intersects(Bound bound) {
		if(bound instanceof BoundRect){
			return intersects((BoundRect)bound);
		}
		return false;
	}

}
